<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>自动跳转</title>
    <style>
        p{
            text-align: center;
        }
        span{
            text-align: center;
            color: red;
        }
    </style>
</head>
<body>
    <p>
        <span id="time">5</span>秒后自动跳转到首页...
    </p>
    <script>
        var time = document.getElementById("time");
        var second = 5;
        function fun(){
            second--;
            if(second===0){
                location.href = "http://www.baidu.com";
            }
            time.innerHTML = second;
        }
        setInterval(fun,1000);
    </script>
</body>
</html>